<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="https://cdn.bootcss.com/blueimp-md5/2.10.0/js/md5.js"></script>
</head>
<body>
<script>

    var appKey = 'xxx'
    var appSecret = 'xxx'
    var signUrl = 'https://testapi.ecloudsign.cn'

    function random(){
        var mm=Math.random();
        var six = "";
        if(mm>0.1)
        {
            six=Math.round(mm*1000000);
        }else{
            mm += 0.1;
            six = Math.round(mm*1000000);
        }
        return six;
    }


    function dateFormat(fmt,date)  {
        var o = {
            "M+" : date.getMonth()+1,                 //月份
            "d+" : date.getDate(),                    //日
            "h+" : date.getHours(),                   //小时
            "m+" : date.getMinutes(),                 //分
            "s+" : date.getSeconds(),                 //秒
            "q+" : Math.floor((date.getMonth()+3)/3), //季度
            "S"  : date.getMilliseconds()             //毫秒
        };
        if(/(y+)/.test(fmt))
            fmt=fmt.replace(RegExp.$1, (date.getFullYear()+"").substr(4 - RegExp.$1.length));
        for(var k in o)
            if(new RegExp("("+ k +")").test(fmt))
                fmt = fmt.replace(RegExp.$1, (RegExp.$1.length==1) ? (o[k]) : (("00"+ o[k]).substr((""+ o[k]).length)));
        return fmt;
    }


    function signData(dt) {
        dt.appKey = appKey
        dt.timestamp = dateFormat("yyyy-MM-dd hh:mm:ss", new Date())
        // dt.timestamp="2021-08-11 15:52:51"
        dt.v = '1.0'
        dt.nonce = random()
        //dt.nonce =  638501

        var date = Object.keys(dt);
        // 对数组进行升序排序
        date.sort()
        console.log(date)
        var str = appSecret
        for (var i = 0; i < date.length; i++) {
            if (dt[date[i]] != null && dt[date[i]] != '') {
                str += dt[date[i]]
            }
        }
        str += appSecret
        console.log(str);
        dt.signature = md5(str).toUpperCase()
        console.log(dt)
    }


    var dt={"returnUrl":"https://www.xxxx.html?param=aaa"   ,"signType":"3","mobilePhone":"18500000000"};
    signData(dt)

    //去手写板
    var sxb_url=signUrl+"/ecs/signApiPage/signPage.jspa?v=1.0&appKey="+appKey+"&nonce="+dt.nonce+
        "&signature="+dt.signature+"&mobilePhone="+dt.mobilePhone+"&signType="+dt.signType+"&returnUrl="+dt.returnUrl+"&timestamp="+dt.timestamp


    window.location.href=sxb_url


</script>
</body>
</html>